package net.jiastudy.core.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.security.core.context.SecurityContextHolder;

import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.jiastudy.biz.user.entity.User;

@ApiResponses({ @ApiResponse(code = 401, message = "没有登录"), @ApiResponse(code = 403, message = "没有权限"),
	@ApiResponse(code = 406, message = "数据校验失败") })
public class BaseController {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	protected ApplicationContext applicationContext;
	
	@Autowired
	protected MessageSource messageSource;

	protected User getCurrentUser() {
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if (null != principal) {
			return (User) principal;
		}
		return null;
	}
}
